package com.snopy.designPattern.structure.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author snopy
 * @version 1.0.0
 * @classname Menu
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/03 10:44
 */
public class Menu {
    private String id;
    private String name;
    private String url;
    private List<Menu> childMenus;

    public Menu(String id,String name, String url) {
        this.id = id;
        this.name = name;
        this.url = url;
        this.childMenus = new ArrayList<>();
    }

    public void addMenu(Menu menu){
        this.childMenus.add(menu);
    }
    public void removeMenu(Menu menu){
        this.childMenus.remove(menu);
    }

    @Override
    public String toString() {
        StringBuffer desc = new StringBuffer();
        for (Menu m:childMenus) {
            desc.append("id="+m.id+"name='" + m.name + '\'' +
                    ", url='" + m.url + '\'');
        }
        return "Menu{" +
                "name='" + name + '\'' +
                ", url='" + url + '\'' +
                '}'+"childMenu={"+desc.toString()+"}";
    }
}
